<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/public/head.jsp" %>
<!DOCTYPE html>
<html style="background-color:#FFFFFF;">

<head>
    <meta charset="utf-8"/>
    <meta name="wap-font-scale" content="no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>个人信息</title>
    <meta name="apple-mobile-web-app-capable" content="no"/>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="stylesheet" href="${system}/static/css/mui_alert.css"/>
    <link rel="stylesheet" href="${system}/static/css/pandastar.css"/>
</head>
<style>

</style>

<body>
<div class="body-container">
    <div class="toper-wrap">
        <div class="toper-box">
            <div class="toper-left" style="padding:0;">
                <a class="cb-sgin" href="">
                    <i class="fa fa-angle-left" aria-hidden="true"></i>
                </a>
            </div>
            <div class="toper-middle" style="padding:0;">
                信息认证
            </div>
            <div class="toper-right" style="padding:0;">

            </div>
        </div>
    </div>
    <div class="datawrap1">
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    姓名:
                </div>
                <div class="databox-left-et">
                    你的姓名
                </div>
            </div>
            <div class="databox-right">
                <input class="text-input" type="text" name="" id="userName" value="" placeholder="姓名" maxlength="100"/>
            </div>
        </div>
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    身份证号:
                </div>
                <div class="databox-left-et">
                    18位身份证号:
                </div>
            </div>
            <div class="databox-right">
                <input class="text-input" type="text" name="" id="idNum" value="" placeholder="身份证" maxlength="18"/>
            </div>
        </div>
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    银行卡号:
                </div>
                <div class="databox-left-et">
                    请输入您所持有银行的银行卡
                </div>
            </div>
            <div class="databox-right">
                <input class="text-input" id="bankNum" type="text" name="" value="" placeholder="银行卡号" maxlength="50"/>
            </div>
        </div>
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    归属银行:
                </div>
                <div class="databox-left-et">
                    银行卡所属银行:
                </div>
            </div>
            <div class="databox-right">
                <div class="Entry-Requirements" id="bank" style="color: gray;">
                    归属银行
                </div>
            </div>
        </div>
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    学历:
                </div>
                <div class="databox-left-et">
                    您的最高学历
                </div>
            </div>
            <div class="databox-right">
                <select id="edu" style="float: right;height: 30px; width:40%;border: none">
                    <c:forEach items="${educations}" var="edu">
                        <option value="${edu.education_id}">${edu.education_name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    地址:
                </div>
                <div class="databox-left-et">
                    户籍所在地
                </div>
            </div>
            <div class="databox-right">
                <input class="text-input" type="text" name="" id="address" value="" placeholder="地址" maxlength="50"/>
            </div>
        </div>
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    紧急联系人:
                </div>
                <div class="databox-left-et">
                    父母孩子或朋友
                </div>
            </div>
            <div class="databox-right">
                <input class="text-input" type="text" name="" id="emergency_contact" value="" placeholder="紧急联系人"
                       maxlength="50"/>
            </div>
        </div>
        <div class="databox">
            <div class="databox-left">
                <div class="databox-left-ct">
                    邀请码:
                </div>
                <div class="databox-left-et">
                    邀请人提供的邀请码
                </div>
            </div>
            <div class="databox-right">
                <input class="text-input" type="text" name="" id="code" value="" placeholder="6位数的邀请码(可选)" maxlength="6"/>
            </div>
        </div>
    </div>
</div>

<div class="signupDataSumbit-wrap">
    <input class="sinputSumbit" type="submit" name="" id="go" value="提交">
</div>
</div>
</body>

<script src="${system}/static/js/rembasic.js" type="text/javascript" charset="utf-8"></script>
<script src="${system}/static/js/bank.js"></script>
<script src="${system}/static/js/bankCardNo.js"></script>
<script src="${system}/static/js/cvi_busy_lib.js"></script>
<script src="${system}/static/js/mui.min.js"></script>
<script src="${system}/static/js/mui.js"></script>
<script>


    var time = 0;
    $("#go").click(function () {
        //判断计时器是否处于关闭状态
        if (time == 0) {
            time = 10; //设定间隔时间（秒）
            //启动计时器，倒计时time秒后自动关闭计时器。
            var index = setInterval(function () {
                time--;
                if (time == 0) {
                    clearInterval(index);
                }
            }, 1000);

//验证姓名的正则表达式
            var v_name = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;
            var user_Name = $("#userName").val();
            if (!v_name.test(user_Name)) {
                mui.toast("姓名必须真实有效!");
                return;
            }

            //身份证号的正则表达式
            var idCard = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
            var id_Number = $("#idNum").val();
            if (!idCard.test(id_Number)) {
                mui.toast("身份证号必须真实有效!");
                return;
            }

            //银行卡号正则表达式
            var v_bank = /^([1-9]{1})(\d{14}|\d{18})$/;
            var bankNum = $("#bankNum").val(); //银行卡号
            if (!v_bank.test(bankNum)) {
                mui.toast("银行卡号必须真实有效!");
                return;
            }

            //地址正则表达式
            var v_address = /^(\w|[\u4E00-\u9FA5\\s]){10,50}$/;
            var address = $("#address").val();
            if (!v_address.test(address)) {
                mui.toast("居住地址必须真实有效!");
                return;
            }

            //手机号正则表达式
            var v_phoneNumber = /^1[34578]\d{9}$/; //手机号表达式
            var emergency_contact = $("#emergency_contact").val();
            if (!v_phoneNumber.test(emergency_contact)) {
                mui.toast("紧急联系人必须真实有效!");
                return;
            }

            //6位邀请码的正则表达式
/*
            var v_code = /^(\d){6}$/;
            var code = $("#code").val();
            if (!v_code.test(code)) {
                mui.toast("邀请码格式错误!");
                return;
            }

*/

            ajax("${system}/loan/status.do","", "text", "post", true, function (data) {
                switch (data) {
                    case "exist":
                        mui.alert("您已认证完成,无需再次认证!", "提示", "OK", function () {
                            window.location.href = "${system}/loan/quota";
                        });
                        break;
                    case "not_exist":
                        //开始认证
                        var xval = getBusyOverlay('viewport', {
                            color: 'black',
                            opacity: 0.75,
                            text: 'viewport: loading...',
                            style: 'text-shadow: 0 0 3px black;font-weight:bold;font-size:16px;color:white'
                        }, {
                            color: '#ff0',
                            size: 100,
                            type: 'o'
                        });
                        xval.settext("正在审核额度，请稍后......");
                        setTimeout(function () {
                            //所有认证信息
                            var data = {
                                "auth_user_name": user_Name,
                                "auth_card_id": id_Number,
                                "auth_bank_number": bankNum,
                                "auth_bank_name": $("#bank").text(),
                                "auth_address": address,
                                "auth_contacts": emergency_contact,
                                "user_code": $("#code").val(),
                                "education_id": $("#edu").val()
                            };
                            ajax("${system}/loan/auth.do", data, "text", "post", true, function (data) {
                                switch (data) {
                                    case "success":
                                        window.location.href = "${system}/loan/quota";
                                        break;
                                    case "fail":
                                        xval.remove();
                                        mui.toast("认证失败!");
                                        break;
                                    case "not_exist":
                                        window.location.href = "${system}/loan/quota";
                                        break;
                                    default:
                                        xval.remove();
                                        mui.toast("认证时出现问题,请稍后再试!");
                                        break;
                                }
                            }, function (error) {
                                xval.remove();
                                console.log(error);
                                mui.toast("请检查你的网络设置!");
                            })
                        }, 9000);
                        break;
                }
            }, function (error) {
                mui.toast("认证时出现问题,请稍后再试!");
            });


            //查询邀请码存不存在
            /*ajax("{system}/user/userCode.do", {"code": code}, "text", "post", true, function (data) {
                switch (data) {
                    //邀请码存在
                    case "exist":

                        break;
                    //邀请码不存在
                    case "not_exist":
                        mui.toast("该邀请码不存在!");
                        break;
                    //出现问题
                    default:
                        mui.toast("认证时出现问题,请稍后再试!");
                        break;
                }
            }, function (error) {
                console.log(error);
                mui.toast("请检查你的网络设置!");
            });*/
        } else {
            mui.alert("不得重复提交多次!", "提示", "OK")
        }
    });


    //动态识别银行
    $("#bankNum").keyup(function () {
        validateBankNo();
    }).blur(function () {
        validateBankNo();
    });

    //自动识别银行卡
    function validateBankNo() {
        var bankNum = $("#bankNum").val(); //银行卡号
        var json = bankCardAttribution(bankNum); //识别时返回json数据,否则返回error
        if (json != 'error') {
            var bankName = json["bankName"];
            $("#bank").text(bankName);
            return true;
        } else {
            $("#bank").text("归属银行");
            return false;
        }
    }


</script>

</html>